package com.danskin.wechat.webapi;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.danskin.wechat.entity.SportsInfo;
import com.danskin.wechat.model.AccessResponse;
import com.danskin.wechat.model.SportsInfoDTO;
import com.danskin.wechat.service.SportsInfoService;

@RestController
@RequestMapping("api/sportsInfo")
public class SportsInfoApiController extends BaseApiController{
	@Autowired
	private SportsInfoService sportsInfoService;
	
	/**
	 * 我要运动
	 * @param appId
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "querySportsInfo/{appId}",method = RequestMethod.POST, produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
	public Object querySportsInfo(@PathVariable("appId") String appId,HttpServletRequest request){
		List<SportsInfo> list = sportsInfoService.querySportsInfo(appId);
		List<SportsInfoDTO> listDto = new ArrayList<SportsInfoDTO>();
		if(list.size()>0){
			for(SportsInfo info:list){
				SportsInfoDTO dto = new SportsInfoDTO();
				dto.setId(info.getId());
				dto.setTitle(info.getTitle());
				dto.setImg(info.getImg());
				dto.setUrl(info.getBannerUrl());
				listDto.add(dto);
			}
		}
		return new AccessResponse<Object>("0", "ok", listDto);
	}
}
